package com.weiyuwqj.server.service.asset.impl;

import com.github.pagehelper.PageHelper;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.BusAssetInvest;
import com.weiyuwqj.api.model.vo.AssetInvestVo;
import com.weiyuwqj.api.service.BusAssetInvestService;
import com.weiyuwqj.server.mapper.BusAssetInvestMapper;
import com.weiyuwqj.server.service.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by zhangyong on 2017/4/10.
 */
@Service("assetsInvestService")
public class BusAssetInvestServiceImpl extends BaseServiceImpl<BusAssetInvest> implements BusAssetInvestService{

    @Autowired
    private BusAssetInvestMapper assetInvestMapper;

    /**
     * 根据itemId查询资产包投资列表
     * @param itemId
     * @return
     */
    @Override
    public List<BusAssetInvest> getAssetInvestListByItemId(Integer itemId) {
        return assetInvestMapper.getAssetInvestListByItemId(itemId);
    }

    @Override
    public PageList getList(Paginator p, Map map) {
        PageHelper.startPage(p.getPageNum(),p.getPageSize());
        List<AssetInvestVo> list = assetInvestMapper.getList(map);
        return new PageList(list);
    }

    @Override
    public List<AssetInvestVo> getList(Map map) {
        List<AssetInvestVo> list = assetInvestMapper.getList(map);
        return list;
    }

    /**
	 * 根据包计划ID获取第一个
	 *
	 * @param packagePlanId 包ID
	 * @return 第一个购买债权的人
	 */
	@Override
	public BusAssetInvest getOldestAssetInvestByPackagePlanId(Integer packagePlanId) {
		return assetInvestMapper.getOldestAssetInvestByPackagePlanId(packagePlanId);
	}

    /**
     * 根据项目id查询记录
     * @param itemId
     * @return
     */
    @Override
    public PageList getInvestListByItemId(Paginator p, Integer itemId) {
        PageHelper.startPage(p.getPageNum(),p.getPageSize());
        List<AssetInvestVo> list = assetInvestMapper.getInvestListByItemId(itemId);
        return new PageList(list);
    }
}
